package com.leedsoft.service;

import com.leedsoft.common.DateUtil;
import com.leedsoft.common.Page;
import com.leedsoft.controller.dto.AidPlanDto;
import com.leedsoft.controller.vo.AidPlanPageVo;
import com.leedsoft.domain.AidPlan;
import com.leedsoft.domain.SysRscDict;
import com.leedsoft.domain.SysRscDictExample;
import com.leedsoft.mapper.AidPlanMapper;
import com.leedsoft.mapper.SysRscDictMapper;
import com.leedsoft.mapper.self.AidPlanSelfMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class AidPlanServiceImpl implements AidPlanService {

    @Autowired
    private SysRscDictMapper sysRscDictMapper;
    @Autowired
    private AidPlanMapper aidPlanMapper;
    @Autowired
    private AidPlanSelfMapper aidPlanSelfMapper;

    @Override
    public List<SysRscDict> getDictList() {
        return sysRscDictMapper.selectByExample(new SysRscDictExample());
    }

    @Override
    public void add(AidPlan aidPlan) {
        aidPlanMapper.insertSelective(aidPlan);
    }

    @Override
    public void update(AidPlan aidPlan) {
        aidPlan.setUpdate_time(DateUtil.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
        aidPlanMapper.updateByPrimaryKeySelective(aidPlan);
    }

    @Override
    public Page<AidPlanDto> getAidPlanPage(AidPlanPageVo planPageVo) {
        Page<AidPlanDto> page = new Page<>(planPageVo);
        int conut = aidPlanSelfMapper.queryAidPlanListCount(planPageVo);
        page.setCount(conut);
        if (conut>0){
            List<AidPlanDto> list = aidPlanSelfMapper.queryAidPlanList(planPageVo);
            page.setList(list);
        }
        return page;
    }

    @Override
    public void delete(long id) {
        aidPlanMapper.deleteByPrimaryKey(id);
    }
}
